Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds option to emit json structured logs #245

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

scottopell
Copy link

@scottopell scottopell commented Sep 28, 2024

This introduces two new options that affect logging output, one that turns on json-formatted logs for the log file option and one for the stdout stream.

      --log-json
          Logging to console (ie, stdout) will emit each log record as a json object

          [env: RQBIT_LOG_JSON=]

      --log-file-json
          Log file will contain json-formatted log records

          [env: RQBIT_LOG_FILE_JSON=]

I think I've managed to not change things too much, lmk what you think

Copy link
Owner

@ikatson ikatson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a fix, at least to unbreak the desktop app.

@scottopell scottopell force-pushed the sopell/structured-stdout branch from b3ca2e0 to dd95c17 Compare October 3, 2024 03:03
@scottopell
Copy link
Author

Thanks for the feedback and pointers, I'm moving this back to a draft for now while I fight with tracing_subscriber

@scottopell scottopell marked this pull request as draft October 3, 2024 03:04
@scottopell scottopell changed the title Adds option to emit json structured logs to stdout Adds option to emit json structured logs Oct 3, 2024
@ikatson
Copy link
Owner

ikatson commented Oct 3, 2024

Also please don't change stderr to stdout for logs. If you really need it for some reason, make it a parameter, but keep the current behavior.

@scottopell
Copy link
Author

I'm misunderstanding where the stdout log stream(s) are coming from, I'm seeing duplicated logs, some with human and some with json. I guess need to revisit all the branches of the logging recorder and see what I missed

$ cargo run -- --log-format=json server start /tmp/scratch 2&>/dev/null
2024-10-03T15:55:58.558134Z  INFO rqbit: inreased open file limit limit=61440
{"timestamp":"2024-10-03T15:55:58.558237Z","level":"INFO","fields":{"message":"inreased open file limit","limit":61440},"target":"rqbit"}

@scottopell scottopell force-pushed the sopell/structured-stdout branch from 6b9c193 to 2ad7128 Compare October 27, 2024 19:00
@scottopell scottopell force-pushed the sopell/structured-stdout branch from a13f938 to 3583c6e Compare November 30, 2024 21:23
@scottopell scottopell marked this pull request as ready for review December 1, 2024 23:00
fmt::layer()
.with_ansi(false)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes log file contain ANSI escape codes which makes it hard to grep and use. Those escape codes are intended for terminal use only.

PR LGTM otherwise, I'd merge if not for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants